const Koa = require('koa');
const app = new Koa();
const KoaRouter = require('koa-router')
const router = new KoaRouter()
const fileRouter = require('./router/file.js')
// Routes
// 默认路由
router.get(`/`, async (ctx) => {
    let ul =`
        <p style="margin-left: 30px;height: 40px;line-height: 40px;">通过Swigger的接口地址，生成本地文件，以下是使用示例：</p>
        <ul>
            <li><strong style="margin-right: 10px;">查看swigger接口:</strong>查看所有的接口地址、名称和请求方式
                <p><a target="_blank" href="http://localhost:5000/getSwigger?src=http://152.136.152.192:7000/smartcity-xxq/v2/api-docs">http://localhost:5000/getSwigger?src=http://152.136.152.192:7000/smartcity-xxq/v2/api-docs</a></p>
            </li>
            <li><strong style="margin-right: 10px;">生成接口函数文件（多）:</strong>将接口函数按路径存到不同的js中
                <p><a target="_blank" href="http://localhost:5000/generateFiles?src=http://152.136.152.192:7000/smartcity-xxq/v2/api-docs">http://localhost:5000/generateFiles?src=http://152.136.152.192:7000/smartcity-xxq/v2/api-docs</a></p>
            </li>
            <li><strong style="margin-right: 10px;">生成接口Map:</strong>生成接口名和地址一一对应的json数据文件
                <p><a target="_blank" href="http://localhost:5000/generateApiMap?src=http://152.136.152.192:7000/smartcity-xxq/v2/api-docs">http://localhost:5000/generateApiMap?src=http://152.136.152.192:7000/smartcity-xxq/v2/api-docs</a></p>
            </li>
            </ul>
`

    ctx.body = ul;
})
app.use(router.allowedMethods()).use(router.routes());
app.use(fileRouter.routes(), fileRouter.allowedMethods())
const port = 5000
app.listen(port, ()=>{
    console.log('server is listening on ' + port)
});
